/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CScrollPane.java
 *
 * Created on Nov 15, 2010, 4:46:11 PM
 */
package org.components.controls;

import java.awt.Color;
import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.LineBorder;

/**
 *
 * @author mjawath
 */
public class CScrollPane extends JScrollPane {

    /**
     * Creates new form BeanForm
     */
    public CScrollPane() {
        initComponents();
    }

    public void initForTable(JTable jtb) {
        JList list = new JList();
        DefaultListModel dlm = new DefaultListModel();
        for (int i = 1; i < 1000; i++) {
            dlm.addElement(i);

        }
        list.setModel(dlm);


        list.setFixedCellHeight(jtb.getRowHeight());
//        list.setBorder( new LineBorder(Color.BLACK) );

        setRowHeaderView(list);
        class MyCellRenderer extends DefaultListCellRenderer {

            /*
             * This is the only method defined by ListCellRenderer. We just
             * reconfigure the Jlabel each time we're called.
             */
            public Component getListCellRendererComponent(
                    JList list,
                    Object value, // value to display
                    int index, // cell index
                    boolean iss, // is the cell selected
                    boolean chf) // the list and the cell have the focus
            {
                /*
                 * The DefaultListCellRenderer class will take care of the
                 * JLabels text property, it's foreground and background colors,
                 * and so on.
                 */
                super.getListCellRendererComponent(list, value, index, iss, chf);

                setBorder(new LineBorder(Color.yellow));
                return this;
            }
        }

//        DefaultListCellRenderer df= new DefaultListCellRenderer();
//
//        df.setBorder(new LineBorder(Color.RED));
//        df.setVerticalAlignment(JLabel.CENTER);
//        list.setCellRenderer(df);
//        df.setSize(50, 60);
//        JLabel renderer = ((JLabel)list.getCellRenderer());
//        renderer.setVerticalAlignment(JLabel.TOP);

        MyCellRenderer cellRenderer = new MyCellRenderer();
        list.setCellRenderer(cellRenderer);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
